let modules = {
	state: {},
	// commit: 同步操作
	mutations: {},
	// 获取器
	getters: {},
	// dispatch: 异步操作
	actions: {}
};

// #ifndef VUE3
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)

const files = require.context("./modules", false, /\.js$/);
files.keys().forEach((key) => {
  Object.assign(modules.state, files(key)["state"]);
  Object.assign(modules.mutations, files(key)["mutations"]);
  Object.assign(modules.getters, files(key)["getters"]);
  Object.assign(modules.actions, files(key)["actions"]);
});

const store = new Vuex.Store(
// #endif

// #ifdef VUE3
import { createStore } from 'vuex';

const files = import.meta.globEager('./modules/*.js');
for (const file in files) {
  // const moduleName = file.replace(/(.*\/)*([^.]+).*/gi, '$2')
  // console.log(moduleName);
  // modules = { ...modules, ...modulesFiles[path] };
  Object.assign(modules.state, file["state"]);
  Object.assign(modules.mutations, file["mutations"]);
  Object.assign(modules.getters, file["getters"]);
  Object.assign(modules.actions, file["actions"]);
}

const store = createStore(
// #endif
	modules
);

export default store
